package com.stars.home.utils

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.*
import com.qmuiteam.qmui.kotlin.onClick
import com.qmuiteam.qmui.layout.QMUIFrameLayout
import com.qmuiteam.qmui.skin.QMUISkinValueBuilder
import com.qmuiteam.qmui.util.QMUIDisplayHelper
import com.qmuiteam.qmui.widget.popup.QMUIPopup
import com.qmuiteam.qmui.widget.popup.QMUIPopups
import com.stars.home.R
import com.stars.home.activity.ArticleDetailActivity
import com.stars.home.inte.ChoiceData
import com.tencent.mmkv.MMKV
import com.trailer.base.utils.B
import com.trailer.base.utils.UiSwitch

/**
 *Created by shihuiyun
 *on 2020/9/21
 */
object PopuLimitUtils {

    fun show(context: Context, view: View, choseData: ChoiceData?) {

        var mNormalPopup = QMUIPopups.fullScreenPopup(context)
        val builder: QMUISkinValueBuilder = QMUISkinValueBuilder.acquire()
        val frameLayout = QMUIFrameLayout(context)
        //自定义布局
        val layoutInflater = context?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        var layout = layoutInflater.inflate(R.layout.item_limit, null)

        val tvOne: TextView = layout.findViewById(R.id.tv_one)
        val tvTwo: TextView = layout.findViewById(R.id.tv_two)
        val tvCancel: TextView = layout.findViewById(R.id.tv_cancel)
        val tvSure: TextView = layout.findViewById(R.id.tv_sure)


        tvOne.onClick {//服务协议

            UiSwitch.bundle(context, ArticleDetailActivity::class.java,
                    B().putString("type","3")
                            .ok())



        }
        tvTwo.onClick {//隐私协议

            UiSwitch.bundle(context, ArticleDetailActivity::class.java,
                    B().putString("type","4")
                            .ok())
        }

        tvCancel.onClick {

            MMKV.defaultMMKV().putBoolean("limits", true)
            choseData?.onRestuse("0")
            mNormalPopup.dismiss()
        }

        tvSure.onClick {
            MMKV.defaultMMKV().putBoolean("limits", true)

            choseData?.onRestuse("1")
            mNormalPopup.dismiss()
        }


        builder.release();

        val size = QMUIDisplayHelper.getScreenWidth(context)


        val lp: FrameLayout.LayoutParams = FrameLayout.LayoutParams(size,
                FrameLayout.LayoutParams.WRAP_CONTENT)
        frameLayout.addView(layout, lp)

        mNormalPopup.addView(frameLayout)
        mNormalPopup.onDismiss() {
            MMKV.defaultMMKV().putBoolean("limits", true)

        }

        mNormalPopup.dismissIfOutsideTouch(false)
        mNormalPopup.animStyle(QMUIPopup.ANIM_GROW_FROM_CENTER)
        mNormalPopup.show(view)


    }


}
